﻿Public Class FormDlnfo
    Private WithEvents UcDigitalKeyboard1 As ucDigitalKeyboard
    Dim objGJBinfo As New clsGJBinfo
    Private Sub FormDlnfo_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        txtDLNo.Focus()
    End Sub

    Private Sub txtDLNo_KeyDown(sender As Object, e As KeyEventArgs) Handles txtDLNo.KeyDown
        If String.IsNullOrEmpty(txtDLNo.Text.Trim) = False Then
            If e.KeyCode = Keys.Enter Then
                search()
            End If
        End If
    End Sub

    Private Sub btnSearch_Click(sender As Object, e As EventArgs) Handles btnSearch.Click
        If String.IsNullOrEmpty(txtDLNo.Text.Trim) = False Then
            search()
        End If
    End Sub

    Private Sub search()
        txtDLNo.Text = txtDLNo.Text.ToUpper()
        Dim dt As DataTable = objGJBinfo.getListByDlNo(txtDLNo.Text.Trim())
        If dt.Rows.Count > 0 Then
            txtDLNo.Tag = dt.Rows(0)("sys_id")
            txtType.Text = dt.Rows(0)("gjb_type")
            txtType.Tag = dt.Rows(0)("material_code")
            If dt.Rows(0)("status").Equals("0") Then
                txtStatus.Text = "未使用"
            Else
                txtStatus.Text = "已使用"
            End If
            txtStatus.Tag = dt.Rows(0)("status")
            txt_assembling_date.Text = dt.Rows(0)("assembling_date")
            txt_exprie_date.Text = dt.Rows(0)("exprie_date")
            txtNum.Text = dt.Rows(0)("layer_num")
            txtWeight.Text = dt.Rows(0)("wt")
        Else
            clear()
            MsgBox("未查询到此骨架板装配记录，请核查！", vbYes, "提示")
        End If
    End Sub

    Private Sub clear()
        txtDLNo.Tag = String.Empty
        txtType.Text = String.Empty
        txtType.Tag = String.Empty
        txtStatus.Text = String.Empty
        txtStatus.Tag = String.Empty
        txtNum.Text = "0"
        txtWeight.Text = "0.0"
    End Sub

    Private Sub txtNum_MouseDown(sender As Object, e As MouseEventArgs) Handles txtNum.MouseDown
        sender.Focus
        UcDigitalKeyboard1 = New ucDigitalKeyboard

        UcDigitalKeyboard1.B_01 = False
        UcDigitalKeyboard1.B_02 = False

        UcDigitalKeyboard1.Txt = sender

        Me.Controls.Add(UcDigitalKeyboard1)
        UcDigitalKeyboard1.Show()
        UcDigitalKeyboard1.BringToFront()
        UcDigitalKeyboard1.Focus()

    End Sub
    Private Sub txtWeight_MouseDown(sender As Object, e As MouseEventArgs) Handles txtWeight.MouseDown
        sender.Focus
        UcDigitalKeyboard1 = New ucDigitalKeyboard

        UcDigitalKeyboard1.B_01 = True
        UcDigitalKeyboard1.B_02 = False

        UcDigitalKeyboard1.Txt = sender

        Me.Controls.Add(UcDigitalKeyboard1)
        UcDigitalKeyboard1.Show()
        UcDigitalKeyboard1.BringToFront()
        UcDigitalKeyboard1.Focus()

    End Sub
    Private Sub ucdigitalkeyboard1_leave(sender As Object, e As EventArgs) Handles UcDigitalKeyboard1.Leave
        UcDigitalKeyboard1.Dispose()
    End Sub

    Private Sub btnSave_Click(sender As Object, e As EventArgs) Handles btnSave.Click
        If String.IsNullOrEmpty(txtDLNo.Text.Trim) = False Then
            If String.IsNullOrEmpty(txtDLNo.Tag.ToString()) = False Then
                If txtStatus.Tag.ToString().Equals("0") Then
                    Dim rtn As Integer = objGJBinfo.save(txtNum.Text.Trim(), txtWeight.Text.Trim(), txtDLNo.Tag.ToString())
                    If rtn <> -2 Then
                        txtDLNo.Text = String.Empty
                        clear()
                        MsgBox("保存成功！", vbYes, "提示")
                    Else
                        MsgBox("保存失败！", vbYes, "提示")
                    End If
                Else
                    MsgBox("该骨架板料框为已使用状态，无法进行修改保存", vbYes, "提示")
                End If
            Else
                MsgBox("未获取到骨架板料框信息，请扫描或输入骨架板料框号", vbYes, "提示")
            End If
        Else
            MsgBox("未获取到骨架板料框信息，请扫描或输入骨架板料框号", vbYes, "提示")
        End If
    End Sub
End Class